package com.wzdigit.wms.wms.controller.TransferWareHouse;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.util.HttpSessionUtil;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.client.response.transfer.HeapAndMergerResponse;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.core.GoodsService;
import com.wzdigit.wms.wms.service.transfer.HeapAndMergerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 在库模块-堆板
 * Created by zyf on 2021/5/10 15:16
 */
@RestController
@Api(tags = "在库模块-堆板")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class HeapAndMergerController {
    private static final String REQUEST_MODEL = "/heapAndMerger";

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private HeapAndMergerService heapAndMergerService;

    /**
     * 堆板
     * @param goodSns
     * @return
     */
    @ApiOperation(value = "堆板",notes = "堆板")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @PostMapping(value = REQUEST_MODEL + "/heapBySns")
    public Result<Integer> heapAndMergerByGoodSns(@Valid @RequestBody List<String> goodSns,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse){
        try {
            return heapAndMergerService.heapAndMerger(goodSns, HttpSessionUtil.getLoginName(servletRequest));
        }catch (RestStatusException e){
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    /**
     * 查询堆板商品信息
     * @param sn
     * @return
     */
    @ApiOperation(value = "查询堆板商品信息",notes = "查询堆板商品信息")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/searchHeap")
    public Result<HeapAndMergerResponse> searchHeapBySn(
            String sn,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
        try {
            return goodsService.selectHeapAndMergerBySn(sn);
        }catch (RestStatusException e){
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }


}
